Skip to content

Pagination for home page and category page #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wishrohitv
Copy link
Contributor

Fixes #

Proposed Changes

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This draft PR implements pagination for both the home and category pages. Key changes include:

  • Addition of a new API endpoint (returnHomeFeedData) and a refactored database query function (getHomeFeedData) to support paginated post retrieval.
  • Updates to the front-end code (HTML template and JavaScript) for rendering post cards with pagination.
  • Removal of redundant database connection code from the index and category routes and registration of new blueprints.

Reviewed Changes

Copilot reviewed 9 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
utils/getHomeFeedData.py Introduces a new function to fetch home feed data with pagination parameters.
static/tailwindUI/pureHtmlMacro/postCardMacro.html Adds an HTML template for post cards used in the home feed.
static/tailwindUI/js/homeFeed.js Updates JS logic to fetch and render paginated posts and handle spinner states.
routes/returnPostAnalyticsData.py Changes the error response to use make_response for consistency.
routes/returnHomeFeedData.py Creates a new endpoint to serve home feed data based on query parameters.
routes/index.py Refactors the home route to remove inline database access and instead defers to external data fetching via blueprints.
routes/category.py Removes the inline DB query in favor of an alternative approach for handling category posts.
modules.py Imports the new getHomeFeedData function.
app.py Registers the new blueprint for the home feed data endpoint.
Files not reviewed (4)
  • templates/tailwindUI/category.html.jinja: Language not supported
  • templates/tailwindUI/components/sortMenu.html.jinja: Language not supported
  • templates/tailwindUI/index.html.jinja: Language not supported
  • templates/tailwindUI/user.html.jinja: Language not supported
Comments suppressed due to low confidence (1)

routes/category.py:109

  • The fetching of post data has been removed from this route without a clear replacement, leaving the template without the expected 'posts' data. Confirm if this change is intentional.
return render_template(..., category=translations["categories"][category.lower()], ...)


// Id
let homeSpinner = document.getElementById("homeSpinner")
let loadMoreSpinner = document.getElementById("lodeMoreSpinner")
Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The element ID 'lodeMoreSpinner' appears to be a typo. Verify if the intended ID is 'loadMoreSpinner'.

Suggested change
let loadMoreSpinner = document.getElementById("lodeMoreSpinner")
let loadMoreSpinner = document.getElementById("loadMoreSpinner")

Copilot uses AI. Check for mistakes.

Comment on lines +67 to +68

if (connection.ok) {
Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable 'posts' is assigned without declaration, which could lead to unintended global scope. Consider declaring it with 'let' or 'const'.

Suggested change
if (connection.ok) {
let posts; // Declare posts locally

Copilot uses AI. Check for mistakes.

Comment on lines 26 to 27
print(category, by, sort, limit, offset, "rohit")

Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected debug print statement ('rohit') found in production code. It should be removed before deployment.

Suggested change
print(category, by, sort, limit, offset, "rohit")

Copilot uses AI. Check for mistakes.

@DogukanUrker
Copy link
Owner

Good job. I love that. we can merge it after fixes. Please check copilot report.

@wishrohitv
Copy link
Contributor Author

Thanks!, I've fixed those typos and bugs

@wishrohitv wishrohitv marked this pull request as ready for review April 26, 2025 17:07
@DogukanUrker DogukanUrker requested a review from Copilot April 26, 2025 19:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements pagination for the home page and category page and refactors the API endpoints to retrieve paginated post data. Key changes include a new utility function for fetching paginated home feed data, updates to the home feed and category routes to remove direct database calls, and integration of front-end logic with a new HTML macro and JavaScript to render posts.

Reviewed Changes

Copilot reviewed 9 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
utils/getHomeFeedData.py New utility function to fetch and return paginated home feed data from the database.
static/tailwindUI/pureHtmlMacro/postCardMacro.html Added HTML macro for rendering individual post cards.
static/tailwindUI/js/homeFeed.js Added JavaScript logic to load, render, and paginate home feed data using the new API.
routes/returnPostAnalyticsData.py Updated the analytics endpoint response with make_response.
routes/returnHomeFeedData.py Introduced a new API endpoint to serve paginated home feed data.
routes/index.py Refactored the home page route to use pagination parameters and remove direct DB calls.
routes/category.py Updated category route to integrate pagination and remove direct DB calls.
modules.py Imported the new getHomeFeedData utility.
app.py Registered the new home feed data blueprint.
Files not reviewed (4)
  • templates/tailwindUI/category.html.jinja: Language not supported
  • templates/tailwindUI/components/sortMenu.html.jinja: Language not supported
  • templates/tailwindUI/index.html.jinja: Language not supported
  • templates/tailwindUI/user.html.jinja: Language not supported

category = request.args.get("category", type=str, default="all")
by = request.args.get("by", type=str, default="hot")
sort = request.args.get("sort", type=str, default="desc")
limit = request.args.get("limit", type=int, default="4")
Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for 'limit' is set as a string instead of an integer; change it to default=4 to ensure correct type conversion.

Suggested change
limit = request.args.get("limit", type=int, default="4")
limit = request.args.get("limit", type=int, default=4)

Copilot uses AI. Check for mistakes.

const tempContainer = document.createElement('div');
tempContainer.innerHTML = postCardHtml;

// Register macro in dome
Copy link
Preview

Copilot AI Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'dome' should be corrected to 'DOM'.

Suggested change
// Register macro in dome
// Register macro in DOM

Copilot uses AI. Check for mistakes.

@DogukanUrker DogukanUrker requested a review from Copilot April 27, 2025 13:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces pagination for the home page and category page by implementing a new home feed data API endpoint and updating the UI to load additional posts. Key changes include:

  • Adding a new API endpoint for home feed data retrieval in routes/returnHomeFeedData.py.
  • Implementing pagination and a "load more" feature in static/tailwindUI/js/homeFeed.js.
  • Removing redundant database connection logic from routes/index.py and routes/category.py and registering the new home feed blueprint in app.py.

Reviewed Changes

Copilot reviewed 9 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
utils/getHomeFeedData.py Introduces a new helper to fetch posts with pagination support.
static/tailwindUI/pureHtmlMacro/postCardMacro.html Adds a template for displaying individual post cards.
static/tailwindUI/js/homeFeed.js Implements fetching and rendering of posts along with pagination logic.
routes/returnPostAnalyticsData.py Updates error response to use make_response.
routes/returnHomeFeedData.py Defines an API endpoint for the home feed data.
routes/index.py Removes redundant DB code and adapts template rendering with new parameters.
routes/category.py Removes redundant DB connection logic for category filtering and sorting.
modules.py Imports the new home feed data function.
app.py Registers the new home feed data blueprint.
Files not reviewed (4)
  • templates/tailwindUI/category.html.jinja: Language not supported
  • templates/tailwindUI/components/sortMenu.html.jinja: Language not supported
  • templates/tailwindUI/index.html.jinja: Language not supported
  • templates/tailwindUI/user.html.jinja: Language not supported

};

// Function to inject html post macro in document body
async function intializePostCard() {
Copy link
Preview

Copilot AI Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name 'intializePostCard' appears to be misspelled; consider renaming it to 'initializePostCard' for clarity.

Suggested change
async function intializePostCard() {
async function initializePostCard() {

Copilot uses AI. Check for mistakes.

@@ -463,6 +466,9 @@ def afterRequest(response):
app.register_blueprint(
returnPostAnalyticsDataBlueprint
) # Registering the blueprint for the postAnalyticsData endpoint route
app.register_blueprint(
returnHomeFeedDataBlueprint
) # Registering the blueprint for the homeFeddData endpoint route
Copy link
Preview

Copilot AI Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment contains a spelling mistake: 'homeFeddData' should be corrected to 'homeFeedData'.

Suggested change
) # Registering the blueprint for the homeFeddData endpoint route
) # Registering the blueprint for the homeFeedData endpoint route

Copilot uses AI. Check for mistakes.

@DogukanUrker
Copy link
Owner

Everything looks perfect but I dont know why your PR breaks timestamp converting.
first image from main branch, and second image from your PRs branch.
Screenshot 2025-04-27 at 16 21 31
Screenshot 2025-04-27 at 16 21 54

@DogukanUrker
Copy link
Owner

@wishrohitv Also I want to ask please explain all new files(why we add them and what they do). Maybe we can find out together

@wishrohitv
Copy link
Contributor Author

Why does Copilot report every new typo instead of pointing them out all at once? 😞

I added following new files:
1 - static/tailwindUI/js/homeFeed.js - perform frontend pagination logic
2 - routes/returnHomeFeedData.py - api endpoint to send home feed data to frontend
3 - static/tailwindUI/pureHtmlMacro/postCardMacro.html - post card macro in html only to work with javascript
3 - utils/getHomeFeedData.py - utils function to query home feed data based on sort, order, category from database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants